package com.sky.controller.admin;

import com.sky.constant.MessageConstant;
import com.sky.result.Result;
import com.sky.service.CommonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName 公共接口
 * @Description TODO
 * @Author 23207
 * @Date 2024/12/11 9:05
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/common")
@Slf4j
public class CommonController {
    @Autowired
    private CommonService commonService;

    /**
     * 图片上传
     *
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) {
        log.info("图片进行上传... {}", file.getName());
        String str = commonService.upload(file);
        if (str != null) {
            return Result.success(str);
        }
        return Result.error(MessageConstant.UPLOAD_FAILED);
    }
}
